package com.csdj.t309.geamtest.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.HashMap;
import java.util.Map;

public class MybatisPuliUtil {
    public static void main(String[] args) {
        //项目的当前路径
        //项目的当前的路径
        String projectPath = System.getProperty("user.dir");
        Map<OutputFile,String> paths = new HashMap<>();
        paths.put(OutputFile.mapper,projectPath.concat("/src/main/java/com/csdj/t309/geamtest/mapper"));
        paths.put(OutputFile.entity,projectPath.concat("/src/main/java/com/csdj/t309/geamtest/entity"));
        paths.put(OutputFile.mapperXml,projectPath.concat("/src/main/java/com/csdj/t309/geamtest/mapper"));
        paths.put(OutputFile.serviceImpl,projectPath.concat("/src/main/java/com/csdj/t309/geamtest/service"));
        paths.put(OutputFile.service,projectPath.concat("/src/main/java/com/csdj/t309/geamtest/service"));
        paths.put(OutputFile.controller,projectPath.concat("/src/main/java/com/csdj/t309/geamtest/controller"));
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/gametest", "root", "123456")
                .globalConfig(builder -> {
                    builder.author("田港") // 设置作者
                            .fileOverride() // 覆盖已生成文件
                            .disableOpenDir()
                            .outputDir(projectPath); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.csdj.t309.geamtest") // 设置父包名
                            .serviceImpl("service")
                            .pathInfo(paths); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("blindbox") // 设置需要生成的表名
                            .controllerBuilder().enableRestStyle()//配置restController
                            .mapperBuilder().enableBaseResultMap().enableBaseColumnList()
                            .serviceBuilder().formatServiceImplFileName("%sService");

                })
                // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
